home *** CD-ROM | disk | FTP | other *** search
- /*
- MultipleChoice.c
- Makes it easy to ask for keyboard responses to multiple-choice questions,
- always providing a default answer, so the user can just hit return.
- Here's an example:
- static char bread[]="Bread",fish[]="Fish",*breadFish[]={bread,fish};
- short choice;
-
- printf("Would you like to eat Bread or Fish?");
- choice=MultipleChoice(choice,2,breadFish);
-
- HISTORY:
- 2/16/93 dgp wrote YesOrNo().
- 5/24/93 dgp added MultipleChoice().
- 9/24/93 dgp cosmetic.
- */
- #include "VideoToolbox.h"
- #if !defined(__TYPES__)
- typedef unsigned char Boolean;
- #endif
-
- Boolean YesOrNo(Boolean defaultAnswer)
- /* Accept y/n and spell out "Yes" or "No". */
- {
- static char no[]="No",yes[]="Yes",*noYes[]={no,yes};
- return MultipleChoice(defaultAnswer,2,noYes);
- }
-
- int MultipleChoice(short defaultChoice,short n,char *answer[])
- /*
- Accept one character answer and spell out whole.
- Case is ignored. Don't wait for <return>. Looks for first match.
- If no match, then uses defaultChoice.
- */
- {
- char c;
- short i;
-
- printf(" (%s):",answer[defaultChoice]);
- fflush(stdout);
- do{
- c=getcharUnbuffered();
- }while(c==-1);
- if(c==14)abort(); /* Crude test for command-period. */
- for(i=0;i<n;i++)if(tolower(c)==tolower((answer[i])[0]))break;
- if(i==n)i=defaultChoice;
- printf("%s.",answer[i]);
- fflush(stdout);
- return i;
- }
-